1. Field of the Invention
The present invention relates to a timer/counter incorporated in a microcomputer, and more specifically to such a timer/counter which can realize a plurality of timer functions by using a plurality of registers in a software manner.
2. Description of Related Art
Heretofore, a timer/counter is adapted to respond to a clock signal from an internal or external clock source so as to increment the value of count in a counter, and to compare the incremented count value with a predetermined value set in a timer register at each time of increment. Then, the timer/counter will generate an interrupt signal which the incremented count value has become consistent with the predetermined value, and at the same time, clear the counter so that the counter can count from its initial value. Furthermore, the timer/counter can execute a capture operation in which the count value in the counter is transferred and held in the timer register in response to a trigger signal which is generated at a predetermined timing or period.
Thus, if an internal clock generated at a constant period is inputted to the counter, an interrupt signal generated when the count value coincides with the preset value of the timer register will be generated at constant intervals determined by the preset value of the timer register. Therefore, the timer/counter can be used as a timer by setting in the timer register a value corresponding to a desired time interval. Alternatively, if an external signal is inputted to the counter as a clock signal, the count value of the counter will represent the pulse number of the external signal. Therefore, the timer/counter can function as an event counter for counting the number of observed events. Furthermore, if the timer/counter is used to function as a timer and also to cause to the timer register to capture the count value of the counter in response to an external signal as the trigger signal, it is possible to measure the period of occurrence of the external signal, and therefore it is possible to know an operation speed or a position of an external equipment which generates the external signal.
As mentioned above, the timer/counter can realize various functions by selecting a clock signal source and by controlling the comparison operation and/or the capture operation. In addition, the various functions can be executed at a real time in parallel to a program operation of the microcomputer. Therefore, the timer/counter has already held an important position in the field of existing single chip microcomputers.
For example, in printers incorporating therein a microcomputer, timer/counters have been used as (1) an internal timer for stepwise changing a phase of a magnetic field applied to a coil of a step motor for moving a printing head; (2) a position detection counter for determining the position of the printing head, (3) a oneshot timer used to control the application time of an electric current to a printing solenoid, etc. As illustrated by this example, there is recently increased a demand for microcomputers to incorporate therein a large number of timer/counters.
In the prior art, however, the timer/counter is composed of a counter or count register for holding a count value, an incrementer for reading the count value of the counter register so as to increment the count value, and a latch for latching the incremented value from the incrementer and updating the content of the count register by the incremented value. Further, the timer/counter comprises a timer register for storing a predetermined value to be compared with the value of the count register or for capturing the value of the count register, and a comparator for comparing the value of the count register with the preset value of the timer register so as to generate an interrupt signal when both the values coincide with each other. Operations of the above various circuits are controlled by a controller. Then, all of the above mentioned various circuits are constituted of random logic circuits, i.e., hardware.
The random logic circuit needs a large number of transistors, and also, the transistors themselves used for the random logic circuit are of a relatively large size. Therefore, in the case that the random logic circuit is realized on an integrated circuit, a considerably large chip area is required. As a result, if a plurality of timer/counters are formed on a single chip, the chip area must be increased, and so, the cost of the single chip computer would inevitably become high. In addition, the random logic circuit has only a limited function, and therefore, when the numbers of the count registers and the timer registers must be changed, it is necessary to refashion the whole of the circuits, which needs even redesigning of mask patterns used in fabrication of integrated circuits.